<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  // 查找0
  // let str = '0101'
  // str = str.replace(/0/g, '<span style="color:red">0</span>')

  // 查找ac,变大写
  // let str2 = "abcabcacb"
  // str2 = str2.replace(/a|c/gi, function (item) {
  //   return `<span style="color:red">${item.toUpperCase()}</span>`
  // })

  // 查找c变大写
  let str3 = "abcabcacb"
  str3 = str3.replace(/c/gi, '<span style="color:red">C</span>')

  //str需要处理的字符串，keyword需要高亮的
  // 封装函数高亮
  function highLight(str, keyword) {
    return str = str.replace(new RegExp(keyword, "gi"), function (item) {
      return `<span style="color:red">${item}</span>`
    })
  }
  let str2 = highLight('asasas', 'a')



  document.body.innerHTML = str2
</script>

</html>